package hr.fer.neumre.gesturerecognizer;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;

/**
 * Glavna aktivnost. Predstavlja "Main menu". 
 * @author Kresimir
 *
 */
public class GestureRecognizerActivity extends Activity {
	private Button btnAddExample;
	private Button btnTrainNet;
	private Button btnRecognizeGesture;
	private Button btnExit;
	
	private static GestureLibrary sStore;
	private final File mStoreFile = new File(Environment.getExternalStorageDirectory(), "gestures");
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        if (sStore == null) {
            sStore = GestureLibraries.fromFile(mStoreFile);
        }
        
        //Otvara se prozor u kojem je moguce dodavati nove geste koje zelimo da mreza nauci
        btnAddExample = (Button) findViewById(R.id.btnAddExample);
        btnAddExample.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				addExampleClick();
			}
		});
        
        //Otvara se novi prozor u kojem je moguce trenirati mrezu
        btnTrainNet = (Button) findViewById(R.id.btnTrain);
        btnTrainNet.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				trainNetworkClick();
			}
		});
        
        //Otvara se novi prozor u kojem se prepozanju geste koje korisnik ucrta
        btnRecognizeGesture = (Button) findViewById(R.id.btnRecognize);
        btnRecognizeGesture.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				recognizeClick();
			}
		});
        
        //Izlaz iz aplikacije
        btnExit = (Button) findViewById(R.id.btnExit);
        btnExit.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				exitClick();
			}
		});
    }
    
    //ovo dolje su pomocne funkcije jer nije dobra praksa pozivati novu Aktivnost direktno iz buttonListenera, nisu toliko bitne
    private void addExampleClick(){
    	Intent i = new Intent(this, AddExampleActivity.class);
    	startActivity(i);
    }
    
    private void trainNetworkClick(){
    	Intent i = new Intent(this, TrainNetActivity.class);
    	startActivity(i);
    }
    
    private void recognizeClick(){
    	Intent i = new Intent(this, RecognizeGestureActivity.class);
    	startActivity(i);
    }
    
    private void exitClick(){
    	finish();
    }
    
    /**
     * Ova funkcija vrace kolekciju gesti.
     * @return
     */
    public static GestureLibrary getStore() {
        return sStore;
    }
}